﻿Public Partial Class _Default2
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
        If (Page.Request.ServerVariables("http_user_agent").ToLower().Contains("chrome")) _
        Or (Page.Request.ServerVariables("http_user_agent").ToLower().Contains("safari")) Then
            Page.ClientTarget = "uplevel"
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            encheBannersLateral()
            EncheMenu()
        End If
    End Sub
    Private Sub encheBannersLateral()
        Dim c As New SiteDLL.Banner
        Try
            c.addWhere("Fixo", ClasseBase.Classes.PersistClass.TipoFiltro.Igual, "Sim")
            c.addWhere(ClasseBase.Classes.PersistClass.OperadorLogico.AND, "Tamanho", ClasseBase.Classes.PersistClass.TipoFiltro.Igual, "P")

            DataList1.DataSource = c.getTodosRegistros
            DataList1.DataBind()
            c.Dispose()
            c = Nothing
        Catch ex As Exception
            Throw ex
        End Try

    End Sub


    Private Sub EncheMenu()

        Dim c As New SiteDLL.Menu
        ' c.addWhere("Topo", ClasseBase.Classes.PersistClass.TipoFiltro.Igual, "Não")
        Dim dt As DataTable = c.getTodosRegistros
        Try
            c.IDMenu = 1
            c.carregar()

            If IsNothing(Session("ContouAcesso")) Then
                Session("ContouAcesso") = True
                c.Acessos = Val(c.Acessos) + 1
                c.salvar()
                c.efetivarTransacao()
            End If
            lblAcesso.Text = "Acessos: " & c.Acessos

            Dim drs() As DataRow = dt.Select("IDPai = 0")
            For Each dr As DataRow In drs
                Dim m As New MenuItem
                m.Value = dr("IDMenu")
                m.Text = dr("Nome")
                m.Target = dr("Target") & ""
                If IsNothing(dr("Url")) Then
                    m.NavigateUrl = "Pagina.aspx?IDPagina=11"
                Else
                    m.NavigateUrl = "ContaClick.aspx?IDMenu=" & dr("IDMenu") & "&Link=" & dr("Url")
                End If

                EncheSub(dt, m)
                Menu1.Items.Add(m)
            Next
        Catch ex As Exception

        Finally
            c.Dispose()
            c = Nothing
            dt.Dispose()
            dt = Nothing
        End Try

    End Sub

    Private Sub EncheSub(ByVal dt As DataTable, ByVal menu As MenuItem)
        Dim drs() As DataRow = dt.Select("IDPai = " & menu.Value)
        For Each dr As DataRow In drs
            Dim m As New MenuItem
            m.Value = dr("IDMenu")
            m.Text = dr("Nome")
            m.Target = dr("Target") & ""
            If IsNothing(dr("Url")) Then
                m.NavigateUrl = "Pagina.aspx?IDPagina=11"
            Else
                m.NavigateUrl = "ContaClick.aspx?IDMenu=" & dr("IDMenu") & "&Link=" & dr("Url")
            End If
            EncheSub(dt, m)
            menu.ChildItems.Add(m)
        Next
    End Sub

    'Private Sub EncheMenuTopo()
    '    Dim c As New SiteDLL.Menu

    '    c.addWhere("Topo", ClasseBase.Classes.PersistClass.TipoFiltro.Igual, "Sim")
    '    Dim dt As DataTable = c.getTodosRegistros
    '    c.Dispose()
    '    c = Nothing
    '    DLMenuTopo.DataSource = dt
    '    DLMenuTopo.DataBind()

    '    dt.Dispose()
    '    dt = Nothing

    'End Sub

    'Protected Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
    '    Response.Redirect("Default.aspx")
    'End Sub

End Class